package com.copa.l461;

/**
 * @author copa
 * @createDate 2022-08-08 16:12
 * @function Brian Kernighan 算法
 */
public class Test2 {

    public int hammingDistance(int x, int y) {
        x ^= y;
        return countOne(x);
    }

    public int countOne(int x) {
        int sum = 0;
        while (x > 0) {
            x = x & (x - 1);
            sum++;
        }
        return sum;
    }

    public static void main(String[] args) {
        int x = 1;
        int y = 4;
        System.out.println(new Test2().hammingDistance(x, y));
    }
}
